<?php


namespace plugin\admin\app\controller\style;


use plugin\admin\app\controller\AuthController;

use plugin\admin\app\exception\AdminException;
use plugin\admin\app\logic\style\OverseaStyleLogic;
use plugin\admin\app\model\style\OverseaStyle;
use support\Request;
use support\Response;

class OverseaStyleController extends AuthController
{

    /**
     * 浏览
     * @return Response
     * @throws \Throwable
     */
    public function index(): Response
    {
        return raw_view('style/index');
    }

    /**
     * 查询
     */
    public function select(Request $request): Response
    {
        return OverseaStyleLogic::getInstance()->select($request);
    }

    /**
     * 更新
     */
    public function update(Request $request): Response
    {
        if ($request->method() === 'POST') {
            return OverseaStyleLogic::getInstance()->update($request);
        }
        return raw_view('style/update');
    }

    /**
     * 插入
     */
    public function insert(Request $request): Response
    {
        if ($request->method() === 'POST') {
            $type = $request->input('type');
            $find = OverseaStyle::getInstance()->getWhere([['type', '=', $type]])->count();
            if ($find) {
                throw new AdminException(4020,'当前类型风格已存在');
            }
            return OverseaStyleLogic::getInstance()->insert($request);
        }
        return raw_view('style/insert');
    }

    /**
     * 删除
     */
    public function delete(Request $request): Response
    {
        return OverseaStyleLogic::getInstance()->delete($request);
    }

    /**
     * 复制
     */
    public function copy(Request $request): Response
    {
        return OverseaStyleLogic::getInstance()->copy($request);
    }
}